package csdn_2;

import java.io.*;

public class Test4 {
    public static void main(String[] args) {
        String path = "D:\\javacode\\javacode\\IO_1\\BufWriter.txt";//写入路径
        String str = "悟已往之不谏，知来者之可追！";//写入内容
        BufferedWriter bufferedWriter=null;
        try {
            bufferedWriter = new BufferedWriter(new FileWriter(path,true));//包装流
            bufferedWriter.write(str);
            bufferedWriter.newLine();//换行
            bufferedWriter.write(str);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            //关闭流, 这里注意，只需要关闭 BufferedWriter ，因为底层会自动的去关闭节点流FileWriter.
            try {
                if (bufferedWriter != null) {
                    bufferedWriter.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
